#include "rast.h"
#include<QString>
#include<QtAlgorithms>
#include <math.h>
#include<QVector>
#include <QtGlobal>
#include<QList>


void Get_Dist(QVector<QVector<double> >& Termdoc,QVector<QVector<double> >& Rast, QString& Rast_Type)
{
    QVector<double> R;
    double x,y,y1,y2;
    for(int i1=0;i1<Termdoc.count();++i1)
    {
        double k=0;
        R.clear();
      for(int i3=0;i3<Termdoc.count();++i3)
      {
           k=k+1;
            x=0;
             y=0;y1=0;y2=0;

        for(int i2=0;i2<Termdoc[1].count();++i2)
        {
            if(Rast_Type=="Evclid"|Rast_Type=="KvEvclid")
            {
            x=x+(Termdoc[i1].value(i2)-Termdoc[i3].value(i2))*(Termdoc[i1].value(i2)-Termdoc[i3].value(i2));
            y=y+(pow(Termdoc[i1].value(i2),2)+pow(Termdoc[i3].value(i2),2));
            }
            if(Rast_Type=="Manhatten")
            {
                x=x+qAbs(Termdoc[i1].value(i2)-Termdoc[i3].value(i2));
                y=y+qAbs(Termdoc[i1].value(i2))+qAbs(Termdoc[i3].value(i2));
            }
            if(Rast_Type=="Chebyshev")
            {
              x=qAbs(Termdoc[i1].value(i2)-Termdoc[i3].value(i2));
              if(x>y) y=x;
              if(Termdoc[i1].value(i2)>y1) y1=Termdoc[i1].value(i2);
              if(Termdoc[i3].value(i2)>y2) y2=Termdoc[i3].value(i2);
            }
            if(Rast_Type=="Cosinus")
            {
             x=x+Termdoc[i1].value(i2)*Termdoc[i3].value(i2);
             y1=y1+(pow(Termdoc[i1].value(i2),2));
             y2=y2+(pow(Termdoc[i3].value(i2),2));
            }
        }
        if(i1==i3 & Rast_Type=="Cosinus")R.append(1);
        else
        {
            if(Rast_Type=="Cosinus")R.append((x/sqrt(y1*y2)));
        }
        if(i1==i3 & Rast_Type!="Cosinus")R.append(0);
        else
        {    
        if(Rast_Type=="Evclid")R.append(sqrt(x/y));
        if(Rast_Type=="KvEvclid")R.append((x/y));
        if(Rast_Type=="Manhatten")R.append((x/y));
        if(Rast_Type=="Chebyshev")R.append(y/qMax(y1,y2));
        }
        }

      Rast.append(R);
    }
}
void GetDistName(QList<QString>& Name)
{
    Name<<"Cosinus"<<"KvEvclid"<<"Manhatten"<<"Chebyshev"<<"Evclid";
}
